package com.dmp.userLabel.factory;

import com.dmp.util.Global;
import redis.clients.jedis.exceptions.JedisException;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by wangqiang on 2016/4/7.
 */
public class ConcreteFactory extends Factory {

    public ILabelRedisDao createLabelRedisDao() {
        String mode = Global.getConfig("car-label.properties","redis.mode");
        if ("1".equals(mode)) {
            return new LabelRedisClusterDao();
        } else {
            return new LabelRedisDao();
        }

    }

    public ILabelRedisDao createLabelRedisDao(String fileName) {
        Properties props = new Properties();
        try {
            props.load(ConcreteFactory.class.getClassLoader().getResourceAsStream(fileName));
        } catch (IOException e) {
            throw (new JedisException("can not load from file:" + fileName));
        }
        String mode = props.getProperty("redis.mode");
        if ("1".equals(mode)) {
            return new LabelRedisClusterDao(fileName);
        } else {
            return new LabelRedisDao(fileName);
        }
    }
}
